/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.maternity.classes.dao;

import br.com.maternity.classes.entity.Medico;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Gattini
 */
public class MedicoDAO extends GenericDAO<Medico> {

    public static Medico instance = new Medico();

    public MedicoDAO() {
        super(instance);
    }

    @Override
    public List<GenericDAOField> listFields() {
        List l = new ArrayList<GenericDAOField>();

        l.add(new GenericDAOField(
                "CRM", "setCrm", "getCrm", Integer.class, true, GenericDAOFieldPrimaryKey.NOTHING));
        l.add(new GenericDAOField(
                "CPF", "setCpf", "getCpf", String.class));
        l.add(new GenericDAOField(
                "Nome", "setNome", "getNome", String.class));

        l.add(new GenericDAOField(
                "Telefone", "setTelefone", "getTelefone", String.class));

        return l;
    }

    @Override
    public String tableName() {
        return "Medico";
    }

    public List<Medico> selectAll() {
        return super.selectList("SELECT * FROM " + tableName());
    }

    public Medico getByCrm(Integer crm) {
        try {
            PreparedStatement ps = super.getPreparedStatement("SELECT * FROM " + tableName() + " WHERE CRM = ?");
            ps.setInt(1, crm);
            return super.select(ps);
        } catch (SQLException sex) {
            return null;
        }

    }

    public Medico getByCpf(String cpf) {
        try {
            PreparedStatement ps = super.getPreparedStatement("SELECT * FROM " + tableName() + " WHERE CPF = ?");
            ps.setString(1, cpf);
            return super.select(ps);
        } catch (SQLException sex) {
            return null;
        }

    }
}
